f = open("scores.hsc", 'r')
scores = f.readlines()
f.close()
#3
score = ""
fixedScores = []

for line in scores:
    for c in line:
        if c != "\n":
            score += c
    fixedScores += [score]
    score = ""
    
title = fixedScores[0]
scores = []

for line in fixedScores[1:]:
    score = []
    score = line.split('|')
    scores += [score]
    
name = raw_input("Enter name: ")
score = raw_input("Enter score: ")

entry = [name, score]

inserted = False
for index, item in enumerate(scores):
    #print item, entry
    if not inserted:
        if int(item[1]) < int(entry[1]):
            scores.insert(index, entry)
            inserted = True
        
if not inserted:
    scores += [entry]
    
for line in scores:
    print line
    
str = title + '\n'
for item in scores:
    str += item[0] + '|' + item[1] + '\n'
    
f = open("scores.hsc", 'w')
f.write(str)
f.close()
    
    
